// 提示词模板接口定义
export interface PromptTemplate {
  id: string;
  name: string;
  description: string;
  category: PromptCategory;
  systemPrompt: string;
  userPromptPrefix?: string;
  variables: PromptVariable[];
  tags: string[];
  version: number;
  createdAt: Date;
  updatedAt: Date;
  isPublic: boolean;
  usageCount: number;
  isStarred?: boolean;
  author?: string;
}

// 提示词变量接口
export interface PromptVariable {
  name: string;                                    // 变量名，如 "topic"
  type: 'string' | 'number' | 'select' | 'boolean';
  required: boolean;
  defaultValue?: any;
  options?: string[];                             // 用于select类型
  validation?: string;                            // 正则表达式
  description?: string;
  placeholder?: string;
  min?: number;                                    // 用于number类型
  max?: number;                                    // 用于number类型
}

// 提示词版本历史
export interface PromptVersion {
  id: string;
  promptId: string;
  version: number;
  content: string;
  systemPrompt: string;
  userPromptPrefix?: string;
  variables: PromptVariable[];
  changelog?: string;
  createdAt: Date;
  createdBy: string;
  isStarred?: boolean;
}

// 提示词分类枚举
export enum PromptCategory {
  ROLE = 'role',           // 角色扮演
  STYLE = 'style',         // 风格控制
  DOMAIN = 'domain',       // 领域专家
  CUSTOM = 'custom',       // 自定义
  CREATIVE = 'creative',   // 创意写作
  TECHNICAL = 'technical', // 技术文档
  BUSINESS = 'business',   // 商务文案
  EDUCATION = 'education', // 教育培训
}

// 预设模板定义
export interface PresetTemplate {
  id: string;
  name: string;
  icon?: string;
  systemPrompt: string;
  userPromptPrefix?: string;
  variables: PromptVariable[];
  category: PromptCategory;
  description: string;
  tags: string[];
  examples?: string[];
}

// 变量替换结果
export interface VariableReplacement {
  original: string;
  replaced: string;
  variables: Record<string, any>;
  errors?: string[];
}

// 提示词测试结果
export interface PromptTestResult {
  id: string;
  promptId: string;
  testInput: string;
  output: string;
  model: string;
  parameters: {
    temperature: number;
    maxTokens: number;
    topP: number;
  };
  responseTime: number;
  tokenCount: {
    input: number;
    output: number;
    total: number;
  };
  score?: number;
  feedback?: string;
  createdAt: Date;
}

// 提示词统计数据
export interface PromptStatistics {
  promptId: string;
  usageCount: number;
  averageScore: number;
  successRate: number;
  lastUsed: Date;
  mostUsedVariables: Record<string, number>;
  userFeedback: {
    positive: number;
    negative: number;
    neutral: number;
  };
  performanceMetrics: {
    averageResponseTime: number;
    averageTokens: number;
    errorRate: number;
  };
}

// 提示词优化建议
export interface PromptOptimization {
  id: string;
  promptId: string;
  suggestions: OptimizationSuggestion[];
  score: number;
  createdAt: Date;
}

export interface OptimizationSuggestion {
  type: 'length' | 'clarity' | 'structure' | 'keywords' | 'variables';
  severity: 'info' | 'warning' | 'error';
  message: string;
  suggestion: string;
  affectedText?: string;
  position?: {
    start: number;
    end: number;
  };
}

// 提示词分享数据结构
export interface PromptShare {
  id: string;
  promptId: string;
  sharedBy: string;
  sharedAt: Date;
  expiresAt?: Date;
  accessCount: number;
  permissions: {
    canView: boolean;
    canCopy: boolean;
    canEdit: boolean;
  };
  shareUrl?: string;
  shareCode?: string;
}

// 提示词导入导出格式
export interface PromptExport {
  version: string;
  exportedAt: Date;
  prompts: PromptTemplate[];
  metadata?: {
    author: string;
    description: string;
    tags: string[];
  };
}

// 变量验证规则
export interface ValidationRule {
  type: 'regex' | 'length' | 'range' | 'custom';
  rule: string | number | { min: number; max: number } | ((value: any) => boolean);
  message: string;
}

// 提示词使用日志
export interface PromptUsageLog {
  id: string;
  promptId: string;
  userId: string;
  usedAt: Date;
  variables: Record<string, any>;
  model: string;
  success: boolean;
  error?: string;
  responseTime: number;
  tokenCount: number;
}